﻿Imports System
Imports System.CodeDom
Imports System.Globalization
Imports System.Text
Imports System.Workflow.ComponentModel.Compiler

Namespace System.Workflow.Activities.Rules
    Friend Class PrimitiveExpression
        Inherits RuleExpressionInternal
        ' Methods
        Friend Overrides Sub AnalyzeUsage(ByVal expression As CodeExpression, ByVal analysis As RuleAnalysis, ByVal isRead As Boolean, ByVal isWritten As Boolean, ByVal qualifier As RulePathQualifier)
        End Sub

        Friend Overrides Function Clone(ByVal expression As CodeExpression) As CodeExpression
            Dim expression2 As CodePrimitiveExpression = DirectCast(expression, CodePrimitiveExpression)
            Return New CodePrimitiveExpression(ConditionHelper.CloneObject(expression2.Value))
        End Function

        Friend Overrides Sub Decompile(ByVal expression As CodeExpression, ByVal stringBuilder As StringBuilder, ByVal parentExpression As CodeExpression)
            Dim expression2 As CodePrimitiveExpression = DirectCast(expression, CodePrimitiveExpression)
            RuleDecompiler.DecompileObjectLiteral(stringBuilder, expression2.Value)
        End Sub

        Friend Overrides Function Evaluate(ByVal expression As CodeExpression, ByVal execution As RuleExecution) As RuleExpressionResult
            Dim expression2 As CodePrimitiveExpression = DirectCast(expression, CodePrimitiveExpression)
            Return New RuleLiteralResult(expression2.Value)
        End Function

        Friend Overrides Function Match(ByVal expression As CodeExpression, ByVal comperand As CodeExpression) As Boolean
            Dim expression2 As CodePrimitiveExpression = DirectCast(expression, CodePrimitiveExpression)
            Dim expression3 As CodePrimitiveExpression = DirectCast(comperand, CodePrimitiveExpression)
            Return ((expression2.Value Is expression3.Value) OrElse (((Not expression2.Value Is Nothing) AndAlso (Not expression3.Value Is Nothing)) AndAlso expression2.Value.Equals(expression3.Value)))
        End Function

        Friend Overrides Function Validate(ByVal expression As CodeExpression, ByVal validation As RuleValidation, ByVal isWritten As Boolean) As RuleExpressionInfo
            If isWritten Then
                Dim item As New ValidationError(String.Format(CultureInfo.CurrentCulture, Messages.CannotWriteToExpression, New Object() { GetType(CodePrimitiveExpression).ToString }), &H17A)
                item.UserData.Item("ErrorObject") = expression
                validation.Errors.Add(item)
                Return Nothing
            End If
            Dim expression2 As CodePrimitiveExpression = DirectCast(expression, CodePrimitiveExpression)
            Return New RuleExpressionInfo(If((Not expression2.Value Is Nothing), expression2.Value.GetType, GetType(NullLiteral)))
        End Function

    End Class
End Namespace

